2024-08-26

R Code

The following code uses the ChickWeight database, which contains the weight data in gram of 48 individual chicks during their growth, as a function of time and diet. There are 4 different diets, and the timeframe goes from 0 to 21 days maximum.

plots <- ChickWeight %>%
  split(.$Diet) %>%
  lapply(function(df) {
    plot_ly(df, x = ~Time, y = ~weight, color = ~Chick, 
            colors = "Set2", type = 'scatter', 
            mode = 'lines+markers', marker = list(size = 5)) %>%
      layout(xaxis = list(title = "Time [days]"),
             yaxis = list(title = "Weight [g]"),
             showlegend = FALSE)
  })

Chick growth trajectories

The plot below shows individual chick weight growth grouped by diet, with each subplot representing a different diet and each curve a different chick.